{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gradient_statsd import Client\n",
    "from datetime import datetime, timedelta\n",
    "from random import randint\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Gradient-Statsd: could not find job handle from environment. logger is not initialized and will not send metrics to statsd\n",
      "sending testMetric1 with counter at 2019-07-06T13:49:56.074034\n",
      "sending testMetric2 with gauge 86 at 2019-07-06T13:49:56.074096\n",
      "sending testMetric1 with counter at 2019-07-06T13:49:58.079205\n",
      "sending testMetric2 with gauge 82 at 2019-07-06T13:49:58.079580\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:00.080782\n",
      "sending testMetric2 with gauge 35 at 2019-07-06T13:50:00.080949\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:02.082799\n",
      "sending testMetric2 with gauge 95 at 2019-07-06T13:50:02.083130\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:04.088517\n",
      "sending testMetric2 with gauge 3 at 2019-07-06T13:50:04.088791\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:06.092590\n",
      "sending testMetric2 with gauge 16 at 2019-07-06T13:50:06.093518\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:08.094396\n",
      "sending testMetric2 with gauge 57 at 2019-07-06T13:50:08.094644\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:10.098645\n",
      "sending testMetric2 with gauge 70 at 2019-07-06T13:50:10.098943\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:12.104327\n",
      "sending testMetric2 with gauge 41 at 2019-07-06T13:50:12.104596\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:14.107646\n",
      "sending testMetric2 with gauge 48 at 2019-07-06T13:50:14.108065\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:16.110771\n",
      "sending testMetric2 with gauge 69 at 2019-07-06T13:50:16.111185\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:18.111495\n",
      "sending testMetric2 with gauge 17 at 2019-07-06T13:50:18.111759\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:20.113888\n",
      "sending testMetric2 with gauge 28 at 2019-07-06T13:50:20.114221\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:22.119525\n",
      "sending testMetric2 with gauge 62 at 2019-07-06T13:50:22.119856\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:24.125270\n",
      "sending testMetric2 with gauge 79 at 2019-07-06T13:50:24.125601\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:26.126786\n",
      "sending testMetric2 with gauge 41 at 2019-07-06T13:50:26.127081\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:28.129569\n",
      "sending testMetric2 with gauge 52 at 2019-07-06T13:50:28.130152\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:30.135599\n",
      "sending testMetric2 with gauge 68 at 2019-07-06T13:50:30.135895\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:32.139237\n",
      "sending testMetric2 with gauge 39 at 2019-07-06T13:50:32.139413\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:34.139822\n",
      "sending testMetric2 with gauge 97 at 2019-07-06T13:50:34.140094\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:36.142728\n",
      "sending testMetric2 with gauge 55 at 2019-07-06T13:50:36.143015\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:38.145458\n",
      "sending testMetric2 with gauge 24 at 2019-07-06T13:50:38.145762\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:40.151261\n",
      "sending testMetric2 with gauge 21 at 2019-07-06T13:50:40.151599\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:42.156970\n",
      "sending testMetric2 with gauge 69 at 2019-07-06T13:50:42.157293\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:44.159685\n",
      "sending testMetric2 with gauge 47 at 2019-07-06T13:50:44.159957\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:46.165339\n",
      "sending testMetric2 with gauge 52 at 2019-07-06T13:50:46.165593\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:48.169729\n",
      "sending testMetric2 with gauge 13 at 2019-07-06T13:50:48.170096\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:50.174972\n",
      "sending testMetric2 with gauge 51 at 2019-07-06T13:50:50.175349\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:52.175763\n",
      "sending testMetric2 with gauge 28 at 2019-07-06T13:50:52.176068\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:54.176336\n",
      "sending testMetric2 with gauge 13 at 2019-07-06T13:50:54.176648\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:56.179715\n",
      "sending testMetric2 with gauge 8 at 2019-07-06T13:50:56.180076\n",
      "sending testMetric1 with counter at 2019-07-06T13:50:58.185418\n",
      "sending testMetric2 with gauge 38 at 2019-07-06T13:50:58.185644\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:00.185823\n",
      "sending testMetric2 with gauge 32 at 2019-07-06T13:51:00.186032\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:02.190828\n",
      "sending testMetric2 with gauge 68 at 2019-07-06T13:51:02.191203\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:04.193732\n",
      "sending testMetric2 with gauge 72 at 2019-07-06T13:51:04.193998\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:06.195530\n",
      "sending testMetric2 with gauge 89 at 2019-07-06T13:51:06.195844\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:08.196304\n",
      "sending testMetric2 with gauge 78 at 2019-07-06T13:51:08.196665\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:10.197202\n",
      "sending testMetric2 with gauge 10 at 2019-07-06T13:51:10.197689\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:12.198156\n",
      "sending testMetric2 with gauge 30 at 2019-07-06T13:51:12.198429\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:14.199057\n",
      "sending testMetric2 with gauge 49 at 2019-07-06T13:51:14.199206\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:16.199808\n",
      "sending testMetric2 with gauge 31 at 2019-07-06T13:51:16.199951\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:18.201770\n",
      "sending testMetric2 with gauge 17 at 2019-07-06T13:51:18.203089\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:20.206681\n",
      "sending testMetric2 with gauge 65 at 2019-07-06T13:51:20.206951\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:22.209212\n",
      "sending testMetric2 with gauge 100 at 2019-07-06T13:51:22.210060\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:24.215522\n",
      "sending testMetric2 with gauge 9 at 2019-07-06T13:51:24.215823\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:26.220204\n",
      "sending testMetric2 with gauge 82 at 2019-07-06T13:51:26.220507\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:28.221242\n",
      "sending testMetric2 with gauge 66 at 2019-07-06T13:51:28.221409\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:30.226250\n",
      "sending testMetric2 with gauge 40 at 2019-07-06T13:51:30.226522\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:32.227033\n",
      "sending testMetric2 with gauge 25 at 2019-07-06T13:51:32.227305\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:34.229971\n",
      "sending testMetric2 with gauge 11 at 2019-07-06T13:51:34.230253\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:36.235877\n",
      "sending testMetric2 with gauge 15 at 2019-07-06T13:51:36.236648\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:38.239408\n",
      "sending testMetric2 with gauge 13 at 2019-07-06T13:51:38.239655\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:40.239819\n",
      "sending testMetric2 with gauge 49 at 2019-07-06T13:51:40.239947\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:42.240806\n",
      "sending testMetric2 with gauge 50 at 2019-07-06T13:51:42.240931\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:44.244179\n",
      "sending testMetric2 with gauge 11 at 2019-07-06T13:51:44.244324\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:46.245337\n",
      "sending testMetric2 with gauge 71 at 2019-07-06T13:51:46.245604\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:48.246250\n",
      "sending testMetric2 with gauge 89 at 2019-07-06T13:51:48.246376\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:50.246534\n",
      "sending testMetric2 with gauge 15 at 2019-07-06T13:51:50.246792\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:52.249176\n",
      "sending testMetric2 with gauge 67 at 2019-07-06T13:51:52.249477\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:54.251550\n",
      "sending testMetric2 with gauge 50 at 2019-07-06T13:51:54.251823\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:56.252602\n",
      "sending testMetric2 with gauge 7 at 2019-07-06T13:51:56.252980\n",
      "sending testMetric1 with counter at 2019-07-06T13:51:58.256943\n",
      "sending testMetric2 with gauge 97 at 2019-07-06T13:51:58.257190\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:00.260872\n",
      "sending testMetric2 with gauge 87 at 2019-07-06T13:52:00.261153\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:02.261658\n",
      "sending testMetric2 with gauge 27 at 2019-07-06T13:52:02.261885\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:04.263460\n",
      "sending testMetric2 with gauge 14 at 2019-07-06T13:52:04.263711\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:06.269085\n",
      "sending testMetric2 with gauge 52 at 2019-07-06T13:52:06.269314\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:08.269599\n",
      "sending testMetric2 with gauge 65 at 2019-07-06T13:52:08.269797\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:10.275093\n",
      "sending testMetric2 with gauge 31 at 2019-07-06T13:52:10.275375\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:12.280685\n",
      "sending testMetric2 with gauge 33 at 2019-07-06T13:52:12.280990\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:14.285519\n",
      "sending testMetric2 with gauge 88 at 2019-07-06T13:52:14.285960\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:16.290914\n",
      "sending testMetric2 with gauge 46 at 2019-07-06T13:52:16.291110\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:18.293052\n",
      "sending testMetric2 with gauge 91 at 2019-07-06T13:52:18.293215\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:20.297061\n",
      "sending testMetric2 with gauge 92 at 2019-07-06T13:52:20.297370\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:22.299401\n",
      "sending testMetric2 with gauge 21 at 2019-07-06T13:52:22.299752\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:24.302689\n",
      "sending testMetric2 with gauge 68 at 2019-07-06T13:52:24.302826\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:26.308095\n",
      "sending testMetric2 with gauge 86 at 2019-07-06T13:52:26.308367\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:28.309865\n",
      "sending testMetric2 with gauge 47 at 2019-07-06T13:52:28.310104\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:30.314162\n",
      "sending testMetric2 with gauge 46 at 2019-07-06T13:52:30.314465\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:32.318250\n",
      "sending testMetric2 with gauge 76 at 2019-07-06T13:52:32.318455\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:34.318660\n",
      "sending testMetric2 with gauge 26 at 2019-07-06T13:52:34.318943\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:36.319911\n",
      "sending testMetric2 with gauge 44 at 2019-07-06T13:52:36.320203\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:38.322073\n",
      "sending testMetric2 with gauge 39 at 2019-07-06T13:52:38.322463\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:40.323278\n",
      "sending testMetric2 with gauge 26 at 2019-07-06T13:52:40.323501\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:42.326810\n",
      "sending testMetric2 with gauge 89 at 2019-07-06T13:52:42.326989\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:44.327411\n",
      "sending testMetric2 with gauge 65 at 2019-07-06T13:52:44.327544\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:46.330307\n",
      "sending testMetric2 with gauge 82 at 2019-07-06T13:52:46.330440\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:48.333534\n",
      "sending testMetric2 with gauge 76 at 2019-07-06T13:52:48.333649\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:50.335342\n",
      "sending testMetric2 with gauge 33 at 2019-07-06T13:52:50.335545\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:52.335717\n",
      "sending testMetric2 with gauge 92 at 2019-07-06T13:52:52.335876\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:54.336013\n",
      "sending testMetric2 with gauge 93 at 2019-07-06T13:52:54.336193\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:56.336619\n",
      "sending testMetric2 with gauge 100 at 2019-07-06T13:52:56.336752\n",
      "sending testMetric1 with counter at 2019-07-06T13:52:58.338969\n",
      "sending testMetric2 with gauge 31 at 2019-07-06T13:52:58.339112\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:00.341405\n",
      "sending testMetric2 with gauge 98 at 2019-07-06T13:53:00.341545\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:02.344749\n",
      "sending testMetric2 with gauge 82 at 2019-07-06T13:53:02.345161\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:04.349522\n",
      "sending testMetric2 with gauge 98 at 2019-07-06T13:53:04.349744\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:06.350059\n",
      "sending testMetric2 with gauge 13 at 2019-07-06T13:53:06.350275\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:08.350647\n",
      "sending testMetric2 with gauge 6 at 2019-07-06T13:53:08.350966\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:10.351264\n",
      "sending testMetric2 with gauge 28 at 2019-07-06T13:53:10.351706\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:12.354148\n",
      "sending testMetric2 with gauge 78 at 2019-07-06T13:53:12.354346\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:14.355504\n",
      "sending testMetric2 with gauge 10 at 2019-07-06T13:53:14.355855\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:16.360656\n",
      "sending testMetric2 with gauge 19 at 2019-07-06T13:53:16.360878\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:18.361488\n",
      "sending testMetric2 with gauge 50 at 2019-07-06T13:53:18.361686\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:20.364543\n",
      "sending testMetric2 with gauge 57 at 2019-07-06T13:53:20.364837\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:22.365700\n",
      "sending testMetric2 with gauge 38 at 2019-07-06T13:53:22.366761\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:24.369827\n",
      "sending testMetric2 with gauge 72 at 2019-07-06T13:53:24.370098\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:26.373225\n",
      "sending testMetric2 with gauge 10 at 2019-07-06T13:53:26.373559\n",
      "sending testMetric1 with counter at 2019-07-06T13:53:28.374861\n",
      "sending testMetric2 with gauge 83 at 2019-07-06T13:53:28.375132\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-2-13532ebc45fd>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m     14\u001b[0m     \u001b[0mclient\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgauge\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mMETRIC2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrandNum\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     15\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 16\u001b[0;31m     \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "METRIC1 = \"testMetric1\"\n",
    "METRIC2 = \"testMetric2\"\n",
    "\n",
    "client = Client()\n",
    "\n",
    "endAt = datetime.now() + timedelta(hours=1)\n",
    "\n",
    "while datetime.now() <= endAt:\n",
    "    print(\"sending {} with counter at {}\".format(METRIC1, datetime.now().isoformat()))\n",
    "    client.increment(METRIC1, 1)\n",
    "\n",
    "    randNum = randint(1, 100)\n",
    "    print(\"sending {} with gauge {} at {}\".format(METRIC2, randNum, datetime.now().isoformat()))\n",
    "    client.gauge(METRIC2, randNum)\n",
    "\n",
    "    time.sleep(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
